package com.edushare.common.mailer;

import java.text.SimpleDateFormat;

import com.edushare.common.util.URLUtils;
import com.edushare.common.vo.OutgoingEmails;
import com.edushare.common.vo.Poll;
import com.edushare.common.vo.Users;

public class NewPoll extends MailStringLoader {

	public NewPoll(Users from, Users to, Poll poll) {
		this.userTo = to;
		init(from, poll);
	}

	private void init(Users from, Poll poll) {
		replaceMap.put("FROM_USER_URL", URLUtils.getHomePageURL(from));
		replaceMap.put("FROM_USER_NAME", from.getCompleteUserName());
		replaceMap.put("POLL_NAME", poll.getPollName());
		replaceMap.put("POLL_TITLE", poll.getPollName());
		replaceMap.put("POLL_END", new SimpleDateFormat("MMM d, yyyy hh:mm a")
				.format(poll.getPollEndDate()));

		replaceMap.put("POLL_URL", URLUtils.getHomePageURL(userTo));
		messageString = templateParser(mailString, replaceMap);
	}

	@Override
	public OutgoingEmails send() {
		OutgoingEmails mail = new OutgoingEmails();
		mail.setContent(messageString);
		mail.setReceiverEmailId(userTo.getEmail());
		mail.setStatus(OutgoingEmails.EMAIL_TO_BE_SENT);
		mail.setCopyType(1);
		mail.setSubject("EduShare new poll notification");
		return mail;
	}

	private String mailString = MailBase.get().stringMap
			.get(MailBase.NEW_POLL_MAIL);
	private Users userTo = null;
}
